<table class="table table-hover">
<thead>
<tr>
  <th>#</th>
  <th>品名</th>
  <th>规格</th>
  <th>产品说明</th>
  <th>产品类别</th>
  <th>产品图片</th>
  <th>操作</th>
</tr>
</thead>
<tbody>
<% for (var i=0; i<data.length; i++) {%>
<tr>
  <th scope="row"><%= i+1 %></th>
  <td><%= data[i].product_name %></td>
  <td><%= data[i].specification %></td>
  <td><%= data[i].info %></td>
  <td><%= data[i].cat%></td>
  <td><div class="img-container"><img src="/img/<%= data[i].img %>"></div></td>
  <td><a class="btn btn-primary" href="/admin/product/delete/<%= data[i].id %>">删除</a></td>
</tr>
<% } %>
</tbody>
</table>
<button type="button" class="btn btn-default" id="btn-add">添加产品</button>
<div id="add-product" style="display: none">
<h1>添加产品</h1>
<form action="/admin/product/add" method="post" enctype="multipart/form-data">
  <div id="form-create">
      <div class="form-group">
        <label for="title-1">品名</label>
        <input type="text" class="form-control" id="title-1" name="p_name" placeholder="品名">
      </div>
      <div class="form-group">
        <label for="title-1">规格</label>
        <input type="text" class="form-control" id="title-1" name="p_spec" placeholder="规格">
      </div>
      <div class="form-group">
        <label for="title-1">产品说明</label>
        <input type="text" class="form-control" id="title-1" name="p_info" placeholder="说明">
      </div>
      <div class="form-group">
        <label for="title-2">类别</label>
        <select class="form-control" name="p_cat" id="cat_select">
        </select>
      </div>
      <div class="form-group">
        <label for="exampleInputFile">产品图片</label>
        <input type="file" id="exampleInputFile" name="p_img">
        <p class="help-block">大小不超过400k</p>
      </div>
      <button type="submit" class="btn btn-default">创建</button>
  </div>
</form>
</div>
<script>
  $(function () {
    $('#btn-add').click(function () {
      $('#add-product').show();
    });
    $.get('/admin/product/getCat', function(callback, stat){
        console.log(callback);
        var cat = callback.data;
        for (var i=0; i<cat.length; i++) {
            $('#cat_select').append('<option>'+cat[i].category_name+'</option>');
        }
    })
  })
</script>
